<template>
	<view>
		<uni-segmented-control :current="current" :values="list" @clickItem="handleOnClickItem" styleType="text" activeColor="#FFCC00"></uni-segmented-control>
		<view class="container" >
			<picker class="dateSeleter" mode="date" :value="seleteDate" @change="handleDateChange">
				<view class="uni-input">{{seleteDate}}</view>
			</picker>
			<view class="out">
				<view class="text">in</view><switch :checked="out" color="#FFCC00" @change="handleStatus"></switch><view class="text">out</view>
			</view>
		    <ShowTable :data="seleteData"></ShowTable>
		</view>
	</view>
</template>

<script>
	import util from "../../util/util.js"
	import ShowTable from "../../component/table/showTable.vue"
	export default{
		
		data(){
			const today=util.getToday()
			return{
				current:0,
				list:[
					"本日","本月","本年"
				],
				tableData:[
					
				],
				seleteDate:today,
				data:[],
				seleteData:[],
				out:true
			}
		},
		methods:{
			handleOnClickItem(event){
				console.log(event)
				this.current=event.currentIndex;
				let index=this.out?this.current*2:this.current*2+1
				this.seleteData=this.data[index]
			},
			handleDateChange(event){
				this.seleteDate=event.detail.value
				console.log(this.seleteDate)
				const res=util.handleDatas(this.seleteDate)
				let arr=[]
				console.log(res)
				for(let x in res){
					arr.push(res[x])
				}
				this.data=arr
				console.log(this.data)
				let index=this.out?this.current*2:this.current*2+1
				this.seleteData=this.data[index]
				console.log(this.seleteData)
			},
			handleStatus(event){
				this.out=event.detail.value
				let index=this.out?this.current*2:this.current*2+1
				this.seleteData=this.data[index]
			}
		},
		components:{
			ShowTable
		},
		async onShow(){
			// if(getApp().globalData.loginUpdate){
			// 	let res=await uniCloud.callFunction({
			// 		name:"getDatas",
			// 		data:{openid:getApp().globalData.userData.openid}
			// 	})
			// 	console.log(res)
			// 	getApp().globalData.loginUpdate=false
			// 	getApp().globalData.listData=res.result
			// }
			const res=util.handleDatas(this.seleteDate)
			let arr=[]
			console.log(res)
			for(let x in res){
				arr.push(res[x])
			}
			this.data=arr
			console.log(this.data)
			this.seleteData=this.data[0]
			console.log(this.seleteData)
			
		},
		onHide(){
			this.current=0
			this.seleteDate=util.getToday()
			this.out=true
		}
	}
</script>

<style>
	.dateSeleter{
		border: 1px solid #8F8F94;
		margin: 40rpx;
		height: 80rpx;
		border-radius:10rpx ;
		line-height: 80rpx;
		position: relative;
	}
	.uni-input{
		   width: 100%;
		   text-align: center;
		}
	.out{
		margin: 20rpx;
	}
    .text{
		display: inline-block;
		margin: 10rpx;
		font-size: 40rpx;
		color: #8F8F94;
	}
</style>
